<template>
	<view class="home">
		<view class="nav-title">
			<image src="/static/images/localShop/icon_more.png" @click="handleBack"></image>
			本地商家
		</view>
		<image :src="$wanlshop.oss(shopInfo.avatar)" class="banner" mode=""></image>
		<view class="banner-btn">
			相册
			<image src="/static/images/localShop/icon_arrow.png" mode=""></image>
		</view>
		<view class="shop-title">
			<text>{{shopInfo.shopname}}</text>
			<image src="/static/images/localShop/icon_sc_y.png" v-if="show" @click="show = !show"></image>
			<image src="/static/images/localShop/icon_sc.png" v-else @click="show = !show"></image>
		</view>
		<view class="shop-address">
			<view>
				<view>{{shopInfo.address}}</view>
				<view>{{shopInfo.city}}</view>
			</view>
			<image src="/static/images/localShop/icon_zd.png" mode=""></image>
		</view>
		<view class="shop-tab">
			<view :class="{'shop-active': current == 1}" @click="changeCurrent(1)">全部商品</view>
			<view :class="{'shop-active': current == 2}" @click="changeCurrent(2)">商家资料</view>
			<view :class="{'shop-active': current == 3}" @click="changeCurrent(3)">店铺评价</view>
		</view>
		<view class="shop" v-if="current == 1">
			<view class="shop-item" v-for="item in list" :key="item.id" >
				<image class="shop-img" :src="$wanlshop.oss(item.image)" mode="" @tap="handleGoods(item.id)"></image>
				<view class="shop-name" @tap="handleGoods(item.id)">{{item.title}}</view>
				<view class="shop-price"  @tap="handleGoods(item.id)">
					<view>
						<text>易货额</text>
						<text>{{item.price}}</text>
					</view>
					<image src="/static/images/localShop/icon_car.png" lazy-load mode="" @tap="handleGoods(item.id)"></image>
				</view>
			</view>
		</view>
		<block v-if="current == 2">
			<view class="shop-info">
				<view class="info-title">企业介绍</view>
				<view class="info-item">
					<view class="info-label">·公司类型：</view>
					<view class="info-value">{{shopInfo.state == 1?'企业':shopInfo.state == 2?'旗舰店':'个体工商户'}}</view>
				</view>
				<view class="info-item">
					<view class="info-label">·联系电话：</view>
					<view class="info-value">{{shopInfo.mobile}}</view>
				</view>
				<view class="info-item">
					<view class="info-label">·公司介绍：</view>
				</view>
				<view class="info-item">
					<view class="info-value">{{shopInfo.description}}</view>
				</view>
			</view>
			<view class="shop-info">
				<view class="info-title">营业执照</view>
				<image :src="$wanlshop.oss(shopInfo.category[0].image)" v-if="shopInfo.category && shopInfo.category.length" class="info-img" mode=""></image>
			</view>
		</block>
		<view class="" v-if="current == 3">
			<view class="shop-info">
				<view class="info-title">全部评价({{shopInfo.commentList.length}}条)</view>
				<block v-for="(item,index) in shopInfo.commentList" :key="item.id">
					<view class="info-user">
						<image :src="item.user.avatar" class="user-avatar" mode=""></image>
						<view class="user-content">
							<view>
								<view>{{item.user.nickname}}</view>
								<image src="/static/images/user/level1.png" class="icon-level" mode=""></image>
							</view>
							<view>
								<image src="/static/images/localShop/icon_sc_y.png" v-for="(el,index) in item.score" :key="index"
									class="icon-sc" mode="">
								</image>
							</view>
						</view>
					</view>
					<view class="info-text">{{item.content}}</view>
					<view>
						<image :src="el" class="info-comment-img" v-for="(el,index) in item.images" :key="el" mode="">
						</image>
					</view>
				</block>
			</view>
		</view>
		<image src="/static/images/localShop/icon_kf.png" class="icon-kf" mode=""></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				current: 1,
				id: '',
				shopInfo: {},
				page: 1,
				list: []
			};
		},
		onLoad(option) {
			this.id = option.id
			this.getShopInfo()
			this.getGoodsList()
		},
		onReachBottom() {
			this.page++
			this.getGoodsList()
		},
		methods: {
			getGoodsList() {
				uni.request({
					url: '/wanlshop/product/lists',
					method: 'GET',
					data: {
						filter: { shop_id: this.id },
						page: this.page
					},
					success: ({ data }) => {
						let res = data
						if (this.page == 1) {
							this.list = res.data
						} else {
							this.list = [...this.list, ...res.data]
						}
					}
				})
			},
			getShopInfo() {
				uni.request({
					url: `/wanlshop/shop/getShopInfo?id=${this.id}`,
					success: ({ data }) => {
						this.shopInfo = data
					}
				})
			},
			handleGoods(id) {
				this.onGoods(id);
			},

			handleBack() {
				uni.navigateBack()
			},
			changeCurrent(val) {
				this.current = val
			}
		}
	}
</script>

<style lang="scss">
	.nav-title {
		position: fixed;
		top: 0px;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		color: #fff;
		font-weight: 800;
		font-size: 36rpx;
		left: 0;
		right: 0;
		z-index: 9;
		padding: 0 24rpx;

		image {
			width: 40rpx;
			height: 40rpx;
			position: absolute;
			left: 24rpx;
			transform: rotate(180deg);
			filter: brightness(2);
			top: 0;
			bottom: 0;
			margin: auto;
		}
	}

	.banner {
		width: 100%;
		height: 542rpx;
	}

	.banner-btn {
		width: 80rpx;
		height: 40rpx;
		background: rgba(40, 42, 47, 0.45);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		position: absolute;
		left: 26rpx;
		top: 400rpx;
		text-align: center;
		line-height: 40rpx;
		font-size: 20rpx;
		color: #fff;

		image {
			width: 20rpx;
			height: 20rpx;
			vertical-align: middle;
			margin-left: 2rpx;
		}
	}

	.shop-title {
		background: #FFFFFF;
		border-radius: 12rpx;
		position: relative;
		margin: 24rpx;
		margin-top: -70rpx;
		padding: 22rpx;
		font-weight: bold;
		font-size: 40rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		text {
			width: 400rpx;
			display: inline-block;
		}

		image {
			width: 48rpx;
			height: 48rpx;
		}
	}

	.shop-address {
		background: #fff;
		padding: 24rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #333;
		margin: 24rpx;
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		view+view {
			color: #999;
		}

		image {
			width: 60rpx;
			height: 60rpx;
			float: right;
		}
	}

	.shop-tab {
		color: #333;
		font-weight: 500;
		font-size: 32rpx;
		transition: all .3s;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 24rpx;

		.shop-active {
			color: #EF5D0F;
			font-weight: 800;
		}
	}

	.shop {
		display: flex;
		flex-wrap: wrap;
		padding: 24rpx;
		justify-content: space-between;

		.shop-item {
			background: #fff;
			padding: 24rpx;
			border-radius: 12rpx;
			font-size: 32rpx;
			font-weight: 500;
			color: #000;
			width: 340rpx;
			margin-bottom: 20rpx;

			.shop-img {
				width: 252rpx;
				height: 252rpx;
				margin: auto;
				margin-bottom: 40rpx;
				display: block;
			}

			.shop-name {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.shop-price {
				font-size: 20rpx;
				color: #ff1111;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 8rpx;

				text+text {
					font-size: 32rpx;
					font-weight: 800;
				}

				image {
					width: 56rpx;
					height: 56rpx;
				}
			}
		}
	}

	.shop-info {
		background: #FFFFFF;
		border-radius: 12rpx;
		padding: 26rpx 36rpx;
		margin: 24rpx;

		.info-title {
			color: #333;
			font-size: 32rpx;
			font-weight: 500;
			position: relative;
			margin-bottom: 20rpx;
		}

		.info-title::before {
			content: '';
			position: absolute;
			width: 138rpx;
			height: 8rpx;
			background: linear-gradient(90deg, #EF430F 0%, #FFFFFF 100%);
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			bottom: -10rpx;
		}

		.info-item {
			padding: 15rpx 0;
			font-size: 28rpx;
			color: #333;
			font-weight: 500;

			.info-label,
			.info-value {
				display: inline-block;
			}
		}

		.info-img {
			width: 100%;
			height: 348rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
		}
	}

	.info-user {
		display: flex;
		align-items: center;
		margin-top: 40rpx;

		.user-avatar {
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
		}

		.user-content {
			font-size: 30rpx;
			font-weight: 500;
			display: flex;
			align-items: center;
			flex: 1;
			justify-content: space-between;
			color: #333;

			.icon-level {
				width: 120rpx;
				height: 40rpx;
			}

			.icon-sc {
				width: 36rpx;
				height: 36rpx;
			}
		}
	}

	.info-text {
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
	}

	.info-comment-img {
		width: 146rpx;
		height: 146rpx;
		border-radius: 12rpx;
		margin-top: 20rpx;
		margin-right: 14rpx;
	}

	.info-comment-img:nth-child(4n) {
		margin-right: 0;
	}

	.icon-kf {
		width: 146rpx;
		height: 146rpx;
		position: fixed;
		right: 24rpx;
		bottom: 240rpx;
	}
</style>